<?php

#################################################
#################################################
#												#
#		SynapseBB - Pre-Alpha					#
#		Programming - Kimmy Andersson			#
#		Copyright �Kimmy Andersson				#
#												#
#################################################
#################################################

#Directory Protection.
#This is where it checks if the script is displayed on index.
if(!$sbb->onIndex) { 
	
	die('<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
	<html>
	<head>
	<title>403 Forbidden</title>
	</head>
	<body>
	<h1>Forbidden</h1>
	<p>You don\'t have permission to access this document.</p>
	<hr>
	</body>
	</html>');
	
}

class sbb_Module {
	
	public function loginModule() {
		
		echo('<form action="?act=login_proc" method="post">Username: <input type="text" name="sbb_form_name" class="sbb_input"/>&nbsp;Password: <input type="password" name="sbb_form_pass" class="sbb_input"/>&nbsp;<input type="submit" value="Login!" class="sbb_input"/></form>');
		
	}
	
	public function categoryDisplay($idString) {
		
		global $sbb;
		global $sbb_fconfig;
		global $sbb_tdef;
		global $_SESSION;
		
		if(!$idString) {
			
			$sbb_sql = 'SELECT * FROM sbb_tb_categories WHERE admin_only<' . ($_SESSION['user_admin'] + 1);
			$sbb_query = mysql_query($sbb_sql) or die(mysql_error());
			
			while($sbb_cat_fetch = mysql_fetch_array($sbb_query)) {
				
				echo('<div id="' . $sbb_tdef->cat_wrapper . '">');
				echo('<div id="' . $sbb_tdef->cat_title . '"><a href="?act=category_display&id=' . $sbb_cat_fetch[0] . '">' . $sbb_cat_fetch[1] . '</a></div>');
				
				$sbb_sqlf = 'SELECT * FROM sbb_tb_forums WHERE cat_id=' . ($sbb_cat_fetch[0]) . ' AND admin_only<' . ($_SESSION['user_admin'] + 1) . ' ORDER BY f_order ASC';
				$sbb_queryf = mysql_query($sbb_sqlf) or die(mysql_error());
				
				while($sbb_forum_fetch = mysql_fetch_array($sbb_queryf)) {
					
					echo('<div id="' . $sbb_tdef->forum_wrapper . '"><table width="100%"><tr>');
					echo('<td width="20%"><a class="' . $sbb_tdef->forum_title . '" href="?act=forum_display&id=' . $sbb_forum_fetch[0] . '">' . $sbb_forum_fetch[2] . '</a><br/>' . $sbb_forum_fetch[3] . '</td>');
					echo('<td width="60%"></td>');
					
					echo('<td valign="top"><div id="' . $sbb_tdef->forum_latest . '">Last post by: <a href="?act=user_display&id=1">Beta Tester</a><br/>In: <a href="?act=topic&id=1">Test Thread</a></div></td>');
					
					echo('</tr></table></div>');
					
				}
				
				echo('</div>');
				
			}
			
		} else {
			
			$sbb_sql = 'SELECT * FROM sbb_tb_categories WHERE admin_only<' . ($_SESSION['user_admin'] + 1) . ' AND id=' . ($idString);
			$sbb_query = mysql_query($sbb_sql);
			
			$sbb_num = mysql_num_rows($sbb_query);
			
			if($sbb_num == 1) {
				
				while($sbb_cat_fetch = mysql_fetch_array($sbb_query)) {
					
					echo('<div id="' . $sbb_tdef->cat_wrapper . '">');
					echo('<div id="' . $sbb_tdef->cat_title . '">' . $sbb_cat_fetch[1] . '</div>');
					
					$sbb_sqlf = 'SELECT * FROM sbb_tb_forums WHERE cat_id=' . ($sbb_cat_fetch[0]) . ' AND admin_only<' . ($_SESSION['user_admin'] + 1) . ' ORDER BY f_order ASC';
					$sbb_queryf = mysql_query($sbb_sqlf) or die(mysql_error());
					
					while($sbb_forum_fetch = mysql_fetch_array($sbb_queryf)) {
						
						echo('<div id="' . $sbb_tdef->forum_wrapper . '"><table width="100%"><tr>');
						echo('<td width="20%"><a class="' . $sbb_tdef->forum_title . '" href="?act=forum_display&id=' . $sbb_forum_fetch[0] . '">' . $sbb_forum_fetch[2] . '</a><br/>' . $sbb_forum_fetch[3] . '</td>');
						echo('<td width="60%"></td>');
						
						echo('<td valign="top"><div id="' . $sbb_tdef->forum_latest . '">Last post by: <a href="?act=user_display&id=1">Beta Tester</a><br/>In: <a href="?act=topic&id=1">Test Thread</a></div></td>');
						
						echo('</tr></table></div>');
						
					}
					
					echo('</div>');
					
				}
				
			} else {
				
				echo('404: Not Found');
				
			}
			
		}
		
	}
	
	public function forumDisplay($idString) {
		
		global $sbb;
		global $sbb_fconfig;
		global $sbb_tdef;
		global $_SESSION;
		
		$sbb_sql = 'SELECT * FROM sbb_tb_forums WHERE admin_only<' . ($_SESSION['user_admin'] + 1) . ' AND id=' . ($idString);
		$sbb_query = mysql_query($sbb_sql);
		
		$sbb_num = mysql_num_rows($sbb_query);
		
		if($sbb_num == 1) {
			
			while($sbb_forum_fetch = mysql_fetch_array($sbb_query)) {
				
				echo('<div id="' . $sbb_tdef->cat_wrapper . '">');
				echo('<div id="' . $sbb_tdef->cat_title . '">' . $sbb_forum_fetch[2] . '</div>');
				echo('<div align="right">Test</div>');
				
				$sbb_sqlf = 'SELECT * FROM sbb_tb_topics WHERE forum_id=' . ($sbb_forum_fetch[0]) . ' AND admin_only<' . ($_SESSION['user_admin'] + 1) . ' ORDER BY date_added DESC';
				$sbb_queryf = mysql_query($sbb_sqlf) or die(mysql_error());
				
				while($sbb_topic_fetch = mysql_fetch_array($sbb_queryf)) {
					
					echo('<div id="' . $sbb_tdef->forum_wrapper . '"><table width="100%"><tr>');
					echo('<td width="20%"><a class="' . $sbb_tdef->forum_title . '" href="?act=topic_display&id=' . $sbb_topic_fetch[0] . '">' . $sbb_topic_fetch[2] . '</a><br/>' . $sbb_topic_fetch[4] . '</td>');
					echo('<td width="60%"></td>');
					
					echo('<td valign="top"><div id="' . $sbb_tdef->forum_latest . '">Last post by: <a href="?act=user_display&id=1">Beta Tester</a><br/>In: <a href="?act=topic_display&id=1">Test Thread</a></div></td>');
					
					echo('</tr></table></div>');
					
				}
				
				echo('</div>');
				
			}
			
		} else {
			
			echo('404: Not Found');
			
		}
		
	}
	
	public function topicDisplay($idString) {
			
		
		
	}
	
	public function mainNavigation() {
		
		echo('<a href="?act=category_display">Home</a> | <a href="?act=gallery">Gallery</a> | <a href="?act=blog">Blogs</a>');
		
	}
	
}

?>